#include "mechanicalspectrum.h"
#include "private/mechanicalspectrumprivatedefine.h"
#include "common/dataspecificationutils.h"
#include "common/binaryprocesshelper.h"
#include "common/xmldocument.h"
#include "private/spectrumdatafilecommondefine.h"
#include "common/xmlprocesshelper.h"
#include <QDebug>

namespace DataSpecificationGW
{
    class MechanicalSpectrumPrivate
    {
    public:
        MechanicalExtInformationPrivate m_stMechanicalExtInformationPrivate;
        MechanicalDataPrivate m_stMechanicalDataPrivate;
    };

    MechanicalSpectrum::MechanicalSpectrum()
        : Spectrum(),
          m_pMechanicalSpectrumPrivate(new MechanicalSpectrumPrivate)
    {
        setSpectrumTypeCode(SPECTRUM_CODE_MECH_MULTI);
    }

    MechanicalSpectrum::~MechanicalSpectrum()
    {
    }

    /************************************************
     * 函数名   : spectrumName
     * 输入参数 : NULL
     * 输出参数 : NULL
     * 返回值   : QString
     * 功能     : 图谱名称
     ************************************************/
    QString MechanicalSpectrum::spectrumName() const
    {
        return STR_FILE_NODE_MECHANICAL;
    }

    /************************************************
     * 函数名   : setMechanicalExtInformation
     * 输入参数 :
       const MechanicalExtInformation& stMechanicalExtInformation: MechanicalExtInformation
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置MechanicalExtInformation
     ************************************************/
    void MechanicalSpectrum::setMechanicalExtInformation(const MechanicalExtInformation& stMechanicalExtInformation)
    {
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit = stMechanicalExtInformation.eAmpUnit;
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit = stMechanicalExtInformation.fAmpLowerLimit;
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit = stMechanicalExtInformation.fAmpUpperLimit;
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint = stMechanicalExtInformation.iDataPoint;
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate = stMechanicalExtInformation.llSampleRate;
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation = stMechanicalExtInformation.eSwitchingOperation;
        m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount = stMechanicalExtInformation.iPowerFreqCycleCount;
    }

    /************************************************
     * 函数名   : setMechanicalData
     * 输入参数 :
       const MechanicalData& stMechanicalData: MechanicalData
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置MechanicalData
     ************************************************/
    void MechanicalSpectrum::setMechanicalData(const MechanicalData& stMechanicalData)
    {
        m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData = stMechanicalData.data;
    }

    /************************************************
     * 函数名   : getMechanicalExtInformation
     * 输入参数 : NULL
     * 输出参数 :
       MechanicalExtInformation& stMechanicalExtInformation: MechanicalExtInformation
     * 返回值   : void
     * 功能     : 获取MechanicalExtInformation
     ************************************************/
    void MechanicalSpectrum::getMechanicalExtInformation(MechanicalExtInformation& stMechanicalExtInformation)
    {
        stMechanicalExtInformation.eAmpUnit = static_cast<AmpUnit>(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit);
        stMechanicalExtInformation.fAmpLowerLimit = m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit;
        stMechanicalExtInformation.fAmpUpperLimit = m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit;
        stMechanicalExtInformation.iDataPoint = m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint;
        stMechanicalExtInformation.llSampleRate = m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate;
        stMechanicalExtInformation.eSwitchingOperation = static_cast<SwitchingOperation>(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation);
        stMechanicalExtInformation.iPowerFreqCycleCount = m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount;
    }

    /************************************************
     * 函数名   : setMechanicalData
     * 输入参数 : NULL
     * 输出参数 :
       MechanicalData& stMechanicalData: MechanicalData
     * 返回值   : void
     * 功能     : 获取MechanicalData
     ************************************************/
    void MechanicalSpectrum::getMechanicalData(MechanicalData& stMechanicalData)
    {
        stMechanicalData.data = m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData;
    }

    /************************************************
     * 函数名   : saveBinarySpectrumExtInfo
     * 输入参数 :
       QDataStream& out: 输出流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存二进制可扩展信息段
     ************************************************/
    bool MechanicalSpectrum::saveBinarySpectrumExtInfo(QDataStream& out)
    {
        out.device()->seek(SPECTRUM_HEADER_LENGTH);

        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUnit) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit;
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpLowerLimit) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit;
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUpperLimit) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit;
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipDataPoint) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint;
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSampleRate) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate;
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSwitchingOperation) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation;
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipPowerFreqCycleCount) out << m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount;

        DataSpecificationUtils::saveBinaryReservedData(SPECTRUM_BASE_LENGTH - out.device()->size(), out);

        return true;
    }

    /************************************************
     * 函数名   : saveXMLSpectrumExtInfo
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
       QDomElement& element: dom元素
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存XML可扩展信息段
     ************************************************/
    bool MechanicalSpectrum::saveXMLSpectrumExtInfo(XMLDocument& xmlDocumentObj, QDomElement& element)
    {
        xmlDocumentObj.beginElement(element);
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_EXTINFORMATION);

        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUnit) xmlDocumentObj.setValue(TEXT_AMP_UNIT, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit));
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpLowerLimit) xmlDocumentObj.setValue(TEXT_AMP_MIN, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit, 'f', 1));
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUpperLimit) xmlDocumentObj.setValue(TEXT_AMP_MAX, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit, 'f', 1));
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipDataPoint) xmlDocumentObj.setValue(TEXT_DATA_COUNT, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint));
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSampleRate) xmlDocumentObj.setValue(TEXT_SAMPLE_RATE, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate));
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSwitchingOperation) xmlDocumentObj.setValue(TEXT_OPR_TYPE, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation));
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipPowerFreqCycleCount) xmlDocumentObj.setValue(TEXT_CYCLE_COUNT, QString::number(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount));

        return true;
    }

    /************************************************
     * 函数名   : saveJSONSpectrumExtInfo
     * 输入参数 :
       rapidjson::Document::AllocatorType& alloc:
       rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存JSON可扩展信息段
     ************************************************/
    bool MechanicalSpectrum::saveJSONSpectrumExtInfo(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& jsonValue)
    {
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUnit) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit, TEXT_AMP_UNIT, alloc, jsonValue);
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpLowerLimit) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit, TEXT_AMP_MIN, alloc, jsonValue);
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUpperLimit) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit, TEXT_AMP_MAX, alloc, jsonValue);
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipDataPoint) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint, TEXT_DATA_COUNT, alloc, jsonValue);
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSampleRate) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate, TEXT_SAMPLE_RATE, alloc, jsonValue);
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSwitchingOperation) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation, TEXT_OPR_TYPE, alloc, jsonValue);
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipPowerFreqCycleCount) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount, TEXT_CYCLE_COUNT, alloc, jsonValue);

        return true;
    }

    /************************************************
     * 函数名   : saveBinarySpectrumData
     * 输入参数 :
       QDataStream& out: 输出流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存二进制图谱数据段
     ************************************************/
    bool MechanicalSpectrum::saveBinarySpectrumData(QDataStream& out)
    {
        if(dataCount() <= 0)
        {
            return false;
        }

        out.device()->seek(SPECTRUM_BASE_LENGTH);

        DataSpecificationUtils::saveBinaryPointerData(out, storageDataType(), m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData.data(), dataCount());

        return true;
    }

    /************************************************
     * 函数名   : saveXMLSpectrumData
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
       QDomElement& element: dom元素
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存XML图谱数据段
     ************************************************/
    bool MechanicalSpectrum::saveXMLSpectrumData(XMLDocument& xmlDocumentObj, QDomElement& element)
    {
        xmlDocumentObj.beginElement(element);
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_DATA);

        int iPerDataSize = perDataSize();
        QString strData = m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData.toBase64();
        xmlDocumentObj.setValue( STR_SPECTRUM_NODE_DATA, strData );

        return true;
    }

    /************************************************
     * 函数名   : saveJSONSpectrumData
     * 输入参数 :
       rapidjson::Document::AllocatorType& alloc:
       rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存JSON图谱数据段
     ************************************************/
    bool MechanicalSpectrum::saveJSONSpectrumData(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& jsonValue)
    {
        if (!m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.bSkipMechStorageData) saveJSONField(m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData, STR_SPECTRUM_NODE_DATA, alloc, jsonValue);

        return true;
    }

    /************************************************
     * 函数名   : parseBinarySpectrumExtInfo
     * 输入参数 :
       QDataStream& in: 输入流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析二进制可扩展信息段
     ************************************************/
    bool MechanicalSpectrum::parseBinarySpectrumExtInfo(QDataStream& in)
    {
        if (!in.device()->seek(SPECTRUM_HEADER_LENGTH))
        {
            qDebug() << "MechanicalSpectrum::parseBinarySpectrumExtInfo failed";
            return false;
        }

        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUnit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpUnit);
        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpLowerLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpLowerLimit);
        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipAmpUpperLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpUpperLimit);
        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipDataPoint, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasDataPoint);
        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSampleRate, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasSampleRate);
        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipSwitchingOperation, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasSwitchingOperation);
        parseBinaryField(in, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bSkipPowerFreqCycleCount, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasPowerFreqCycleCount);

        return in.status() == QDataStream::Ok;
    }

    /************************************************
     * 函数名   : parseXMLSpectrumExtInfo
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析XML可扩展信息段
     ************************************************/
    bool MechanicalSpectrum::parseXMLSpectrumExtInfo(XMLDocument& xmlDocumentObj)
    {
        xmlDocumentObj.beginElement(spectrumName());
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_EXTINFORMATION);

        parseXMLField(xmlDocumentObj, TEXT_AMP_UNIT, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpUnit);
        parseXMLField(xmlDocumentObj, TEXT_AMP_MIN, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpLowerLimit);
        parseXMLField(xmlDocumentObj, TEXT_AMP_MAX, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpUpperLimit);
        parseXMLField(xmlDocumentObj, TEXT_DATA_COUNT, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasDataPoint);
        parseXMLField(xmlDocumentObj, TEXT_SAMPLE_RATE, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasSampleRate);
        parseXMLField(xmlDocumentObj, TEXT_OPR_TYPE, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasSwitchingOperation);
        parseXMLField(xmlDocumentObj, TEXT_CYCLE_COUNT, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasPowerFreqCycleCount);

        xmlDocumentObj.endElement();
        xmlDocumentObj.endElement();

        return true;
    }

    /************************************************
     * 函数名   : parseJSONSpectrumExtInfo
     * 输入参数 :
       const rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析JSON可扩展信息段
     ************************************************/
    bool MechanicalSpectrum::parseJSONSpectrumExtInfo(const rapidjson::Value& jsonValue)
    {
        parseJSONField(jsonValue, TEXT_AMP_UNIT, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucAmpUnit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpUnit);
        parseJSONField(jsonValue, TEXT_AMP_MIN, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpLowerLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpLowerLimit);
        parseJSONField(jsonValue, TEXT_AMP_MAX, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.fAmpUpperLimit, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasAmpUpperLimit);
        parseJSONField(jsonValue, TEXT_DATA_COUNT, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasDataPoint);
        parseJSONField(jsonValue, TEXT_SAMPLE_RATE, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.llSampleRate, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasSampleRate);
        parseJSONField(jsonValue, TEXT_OPR_TYPE, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.ucSwitchingOperation, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasSwitchingOperation);
        parseJSONField(jsonValue, TEXT_CYCLE_COUNT, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iPowerFreqCycleCount, m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.bHasPowerFreqCycleCount);

        return true;
    }

    /************************************************
     * 函数名   : parseBinarySpectrumData
     * 输入参数 :
       QDataStream& in: 输入流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析二进制图谱数据段
     ************************************************/
    bool MechanicalSpectrum::parseBinarySpectrumData(QDataStream& in)
    {
        if (!in.device()->seek(SPECTRUM_BASE_LENGTH))
        {
            qDebug() << "MechanicalSpectrum::parseBinarySpectrumData failed";
            return false;
        }

        DataSpecificationUtils::parseBinaryPointerData(in, storageDataType(), m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData, dataCount());

        return in.status() == QDataStream::Ok;
    }

    /************************************************
     * 函数名   : parseXMLSpectrumData
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析XML图谱数据段
     ************************************************/
    bool MechanicalSpectrum::parseXMLSpectrumData(XMLDocument& xmlDocumentObj)
    {
        xmlDocumentObj.beginElement(spectrumName());
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_DATA);

        m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData = QByteArray::fromBase64(xmlDocumentObj.value(STR_SPECTRUM_NODE_DATA).toLatin1());

        xmlDocumentObj.endElement();
        xmlDocumentObj.endElement();

        return true;
    }

    /************************************************
     * 函数名   : parseJSONSpectrumData
     * 输入参数 :
       const rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析JSON图谱数据段
     ************************************************/
    bool MechanicalSpectrum::parseJSONSpectrumData(const rapidjson::Value& jsonValue)
    {
        parseJSONField(jsonValue, STR_SPECTRUM_NODE_DATA, m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.qbaMechStorageData, m_pMechanicalSpectrumPrivate->m_stMechanicalDataPrivate.bHasMechStorageData);

        return true;
    }

    int MechanicalSpectrum::dataCount()
    {
        return m_pMechanicalSpectrumPrivate->m_stMechanicalExtInformationPrivate.iDataPoint;
    }
}
